#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#ifdef DEBUG
#include <iostream>
#endif
const int N = 1e5, M = 1e7, mod = 1e8;
int n, dans[N];

struct BigBitNum {
  std::bitset<M> bs;
  int len;
  BigBitNum() : len(-1) {}
} a, bans;

inline void addbit(BigBitNum &lhs, int pos) {
  while (lhs.bs[pos]) lhs.bs.set(pos, false), pos++;
  lhs.bs.set(pos, true);
  lhs.len = std::max(lhs.len, pos);
}

inline bool check() {
  for (int i = ((a.len + 1) >> 1), j = a.len - i; i <= a.len; ++i, --j) {
    if (a.bs.test(i) > a.bs.test(j)) return false;
    if (a.bs.test(i) < a.bs.test(j)) return true;
  }
  return true;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P2235 [HNOI2002]Kathy函数.in", "r", stdin);
  freopen("P2235 [HNOI2002]Kathy函数.out", "w", stdout);
#endif
#endif

  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    if (~a.len) {
      a.len += 3;
      for (int i = a.len; ~i; --i) {
        a.bs.set(i, false);
        if (i > 0 && a.bs.test(i - 1)) addbit(a, i);
        if (i > 2 && a.bs.test(i - 3)) addbit(a, i);
      }
    }
    switch (ch - '0') {
      case 1:
        addbit(a, 0);
        break;
      case 2:
        addbit(a, 1);
        break;
      case 3:
        addbit(a, 0), addbit(a, 1);
        break;
      case 4:
        addbit(a, 2);
        break;
      case 5:
        addbit(a, 0), addbit(a, 2);
        break;
      case 6:
        addbit(a, 1), addbit(a, 2);
        break;
      case 7:
        addbit(a, 0), addbit(a, 1), addbit(a, 2);
        break;
      case 8:
        addbit(a, 3);
        break;
      case 9:
        addbit(a, 0), addbit(a, 3);
        break;
    }
    ch = getchar();
  }
  for (int i = 1; i <= a.len; ++i) { addbit(bans, (i - 1) >> 1); }
  for (int i = (a.len + 1) >> 1, j = 0; i < a.len; ++i, ++j) {
    if (a.bs.test(i)) addbit(bans, j);
  }
#ifdef DEBUG
  std::cerr << a.len << std::endl;
  assert(check());
#endif
  if (check()) addbit(bans, 0);
  while (~bans.len) {
    int add = bans.bs.test(bans.len--);
    for (int i = 1; i <= dans[0]; ++i) {
      dans[i] = (dans[i] << 1) + add;
      add = dans[i] / mod;
      dans[i] %= mod;
    }
    while (add) {
      dans[++dans[0]] = add;
      add = dans[dans[0]] / mod;
      dans[dans[0]] %= mod;
    }
  }
  printf("%d", dans[dans[0]]);
  for (int i = dans[0] - 1; i > 0; --i) { printf("%08d", dans[i]); }
  return 0;
}